<?php
class ControllerMartCrmManagePoint extends Controller {  
  	public function index() {
		$this->load->language('Mart_Crm/Manage_Point');	
    	        $this->document->setTitle($this->language->get('heading_title'));
//phuong thuc request->get[''] dung de lay gia tri tu o text cua html thong qua 1 cai ham tra ve cua no           
                if (isset($this->request->get['start_time'])) {
			$starttime = $this->request->get['start_time'];
                        $start_time = date('d-m-Y',strtotime($starttime));  
		} else {
			$start_time = NULL;
		}
                
                if (isset($this->request->get['end_time'])) {
			$endtime = $this->request->get['end_time'];
                        $end_time = date('d-m-Y',strtotime($endtime));  
		}else {
			$end_time = NULL;
		} 
                if (isset($this->request->get['B'])) {
			$B = $this->request->get['B'];
		}else {
			$B = NULL;
		}
                if (isset($this->request->get['Bt'])) {
			$Bt = $this->request->get['Bt'];
		}else {
			$Bt = NULL;
		}
                if (isset($this->request->get['Rs'])) {
			$Rs = $this->request->get['Rs'];
		}else {
			$Rs = NULL;
		}
                if (isset($this->request->get['Rg'])) {
			$Rg = $this->request->get['Rg'];
		}else {
			$Rg = NULL;
		}
                if (isset($this->request->get['Psliver'])) {
			$Psliver = $this->request->get['Psliver'];
		}else {
			$Psliver= NULL;
		}
                if (isset($this->request->get['Pgold'])) {
			$Pgold= $this->request->get['Pgold'];
		}else {
			$Pgold= NULL;
		}
                if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}
//                $url = '';
//		
//		if (isset($this->request->get['start_time'])) {
//                        $starttime = urlencode($this->request->get['start_time']);
//			$url .= '&start_time=' . date('d-m-Y',strtotime($starttime)); 
//		}
//		
//		if (isset($this->request->get['end_time'])) {
//                        $endtime = $this->request->get['filter_ip'];
//			$url .= '&filter_ip=' . $this->request->get['filter_ip'];
//		}
//						
//		if (isset($this->request->get['page'])) {
//			$url .= '&page=' . $this->request->get['page'];
//		}
                $update = array(
                  'B'      => $B,
                  'Bt'     => $Bt,
                  'Rs'     => $Rs,
                  'Rg'     => $Rg,
                  'Psliver'=> $Psliver,
                  'Pgold'  => $Pgold,
                  'TD1'    => $start_time,
                  'TD2'    => $end_time
                );
                
		$url = '';
                 
                $this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token']),
       		'text'      => $this->language->get('text_home'),
      		'separator' => false
   		);
   		$this->data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('Mart_Crm/Manage_Point', 'token=' . $this->session->data['token'] . $url),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);
                $status = "";
                $this->load->model('Mart_Crm/Manage_Point');
                if(isset($this->request->get['start_time'])&&isset($this->request->get['end_time'])&&isset($this->request->get['B'])&&isset($this->request->get['Bt'])&&isset($this->request->get['Rs'])&&isset($this->request->get['Rg'])&&isset($this->request->get['Psliver'])&&isset($this->request->get['Pgold'])&&(strtotime($start_time)< strtotime($end_time)))
                {
                  $this->model_Mart_Crm_Manage_Point->update($update);   
                  $status = "Thay Đổi Của Bạn Đã Được Cập Nhập Thành Công!";
                }
                if(isset($this->request->get['start_time'])&&isset($this->request->get['end_time'])&&isset($this->request->get['B'])&&isset($this->request->get['Bt'])&&isset($this->request->get['Rs'])&&isset($this->request->get['Rg'])&&isset($this->request->get['Psliver'])&&isset($this->request->get['Pgold'])&&(strtotime($start_time)>= strtotime($end_time)))
                {
                 // $this->model_Mart_Crm_Manage_Point->update($update);   
                  $status = "Thời gian thiết lập không chính xác "."\r\n"." Thời điểm bắt đầu nhỏ hơn thời điểm kết thúc!";
                }
                $this->data['status'] = $status;
                $parameter = $this->model_Mart_Crm_Manage_Point->getParameter();             
 //toan tu data dung de truyen(day) du lieu cho bien o ben html
                $this->data['heading_title'] = $this->language->get('heading_title');
                $this->data['text_no_results'] = $this->language->get('text_no_results');	
		$this->data['start_time'] = $this->language->get('start_time');
		$this->data['end_time'] = $this->language->get('end_time');
		$this->data['B'] = $this->language->get('B');
		$this->data['Bt'] = $this->language->get('Bt');
		$this->data['Rs'] = $this->language->get('Rs');
		$this->data['Rg'] = $this->language->get('Rg');
                $this->data['Psliver'] = $this->language->get('Psliver');
                $this->data['Pgold'] = $this->language->get('Pgold');
//dong 123 dung de xu ly button cap nhap o ben html xay ra
                $this->data['token'] = $this->session->data['token'];
                
                $TD1     = $parameter[0]['TD1'];
                $TD2     = $parameter[0]['TD2'];
                $B       = $parameter[0]['B']; 
                $Bt      = $parameter[0]['Bt'];
                $Rs      = $parameter[0]['Rs'];
                $Rg      = $parameter[0]['Rg'];
                $Pgold   = $parameter[0]['Pgold'];
                $Psliver = $parameter[0]['Psliver'];
                $this->data['TD1'] = $TD1;
                $this->data['TD2'] = $TD2;
                $this->data['b'] = $B;
                $this->data['bt'] = $Bt;
                $this->data['rs'] = $Rs;
                $this->data['rg'] = $Rg;
                $this->data['psliver'] = $Psliver;
                $this->data['pgold'] = $Pgold;
                      
		$this->template = 'Mart_Crm/Manage_Point.tpl';        
                $this->children = array(
			'common/header',	
			'common/footer'	
		);
		
		$this->response->setOutput($this->render());
  	}
}
?>
